import React, { PureComponent } from 'react';
import _ from 'lodash';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Tabs } from 'antd';
import { ContentPackage } from '../../../comps';
import NonstandardValueReviewC from './nonstandardValueReviewC';
import NonstandardLossRatioC from './nonstandardLossRatioC';
import config from '../../../utils/tableMoreIdConfig';
const { TabPane } = Tabs;

import { connect } from 'dva';
import { findValueByCode } from '../../../utils/utils';
const {
  nonstandardValueTab: { marketMethodTable, amortizedCostTable, costTable, nonstandardLossTable },
} = config;
@Form.create()
@connect(({ nonstandardValueReviewM, globalM }) => ({ nonstandardValueReviewM, globalM }))
export default class NonstandardValueTab extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      activeKey: '1',
    };
  }
  componentDidMount() {
    this.queryCustodianList();
    // 适配用户视图跳转至成本法tab页
    if (!!sessionStorage.getItem('jumpInfo')) {
      const obj = JSON.parse(sessionStorage.getItem('jumpInfo'));
      if (obj.activeKey == '3') {
        this.setState({
          activeKey: obj.activeKey,
        });
        sessionStorage.removeItem('jumpInfo');
      }
    }

    //  更新未读消息---用于用户视图数据
    this.props.dispatch({
      type: 'nonstandardValueReviewM/updateUnreadDate',
      payload: {
        msgType: '1',
      },
    });
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    // 适配用户视图跳转至成本法tab页
    if (!!sessionStorage.getItem('jumpInfo')) {
      const obj = JSON.parse(sessionStorage.getItem('jumpInfo'));
      if (obj.activeKey == '3') {
        this.setState({
          activeKey: obj.activeKey,
        });
        sessionStorage.removeItem('jumpInfo');
      }
    }
  }
  //获取托管人名称
  queryCustodianList = () => {
    const {
      globalM: {
        dataDictionary: { BAXX_JNTGJGMC = [] },
      },
    } = this.props;
    this.props.dispatch({
      type: 'nonstandardValueReviewM/queryCustodianList',
      payload: {},
      callback: (data) => {
        if (data) {
          data.map((item) => {
            item.title = findValueByCode(item.value, BAXX_JNTGJGMC);
          });
        }
        this.setState({
          custodianList: data || [],
        });
      },
    });
  };

  onChange = (activeKey) => {
    this.setState({
      activeKey: activeKey,
    });
  };
  render() {
    return (
      <ContentPackage
        title='非标估值复核'
        contentHtml={
          <div>
            <Tabs activeKey={this.state.activeKey} onChange={this.onChange}>
              <TabPane tab='市价法' key='1'>
                <NonstandardValueReviewC type={'1'} setId={marketMethodTable} custodianList={this.state.custodianList || []} />
              </TabPane>
              {/* <TabPane tab="摊余成本法" key="2">
                        <NonstandardValueReviewC
                            type={'2'}
                            setId={amortizedCostTable}
                        />
                    </TabPane> */}
              <TabPane tab='成本法' key='3'>
                <NonstandardValueReviewC setId={costTable} custodianList={this.state.custodianList || []} type={'3'} />
              </TabPane>
              <TabPane tab='预期信用损失比例' key='4'>
                <NonstandardLossRatioC setId={nonstandardLossTable} />
              </TabPane>
            </Tabs>
          </div>
        }
      />
    );
  }
}
